<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Error extends Controller_Base {
    
    public $properties = array();
    
    public function before()
    {
        parent::before();
        
        // Получаем статус ошибки
        $status = (int)$this->request->action();

        // Получаем сообщение об ошибке
        $this->properties['message'] = null;
        if (Request::$initial !== Request::$current) {
            $message = rawurldecode($this->request->param('message'));
                    
            if ($message) {
                $this->properties['message'] = $message;
            }
        } else {
            $this->request->action(404);
        }
        $this->response->status($status);
    }
    
    
    public function action_404()
    {
        $content = new View('error/404_tpl');
        $content->message    = $this->properties['message'];
        $content->categories = ORM::factory('category')->where('id', 'IN', array(1729, 1824, 1872, 1923))->find_all(); 
        $this->print_template('Page Not Found', $content);
    }

    public function action_503()
    {
        $content = new View('error/503_tpl');
        $content->message = $this->properties['message']; 
        $this->print_template('Service Temporarily Unavailable', $content);
    }

    public function action_500()
    {
        $content = new View('error/500_tpl');
        $content->message    = $this->properties['message'];
        $content->categories = ORM::factory('category')->where('id', 'IN', array(1729, 1824, 1872, 1923))->find_all(); 
        $this->print_template('Internal Server Error', $content);
    }

}
